<template>
  <div class="tab-control">
    <div v-for="(item, index) in title" :key="index" class="tab-control-item" :class="{active: index === activeItem}" @click="changeTab(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>
<script>
export default {
  name: "TabControl",
  props: {
    title: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data () {
    return {
      activeItem: 0,
    };
  },
  methods:{
    changeTab(val){
      this.activeItem = val;
      this.$emit('changeTab', val)
    }
  }
}
</script>
<style scoped>
  .tab-control {
    display: flex;
    width: 100%;
    height: 44px;
    line-height: 44px;
    text-align: center;
    background: #fff;
  }
  .tab-control-item {
    flex: 1;
  }
  .active span {
    padding: 5px;
    border-bottom: 2px solid var(--color-high-text);
    color: var(--color-high-text);
  }
</style>